library(tidyverse)
library(plotly) # for interactive plotting
This notebook demonstrates the calculation of RMS using the SAE guideline.
The SAE RMS formula definition is: \[ i_{(rms)} = \sqrt{\frac{\int_0^T i(t)^2 dt}{T}} \] Where \[i\] is the current, and \[T\] is the size of the window over which the RMS is calculated.
Assuming an square signal in a canonical form, the apparent average of a waveform in a cycle T is: \[ i_{(average)} = D * i_{max} \]
Where D is the Duty Cycle calculated as the percentage of the time when the waveform is on. Since the waveform is in a canonical squared function, D is simply calculated as: \[ D = \frac{t_{on}}{t_{cycle}} \] Please note that The average of a signal is lower than the RMS. For sinusoidal signals, there is a form factor that helps to go from the average to the RMS:
Initializing a variable with the pre-defined parameters characteristics
# Parameters
i_amp <- 18 # Instant current amplitude
pulseWidth_PW <- 50 * 1e-06 # parameter in microseconds, resulting value in seconds
cycleDuration <- 20 * 1e-03 # parameter in in milliseconds, resulting value in seconds
electrodeArea <- 1.44 # Area of the electrode in cm^2
samplingRate <- 100000 # in Hz: 100 000 data points every 1 second
pulseTrainDuration_PT <- 2 # in seconds
# Calculated parameters
delayBetweenPulses_PD <- cycleDuration - (2 * pulseWidth_PW) # in seconds
numberPulsesInTrain <- pulseTrainDuration_PT / cycleDuration # it must be an integer result for simplicity
# Wave
currentWave <- rep(
c(rep(i_amp, pulseWidth_PW*samplingRate),
rep(-i_amp, pulseWidth_PW*samplingRate),
rep(0, delayBetweenPulses_PD*samplingRate)),
numberPulsesInTrain
)
# Timeline
sampleNumber <- c(1:length(currentWave))
# Convert as data frame
currentWave_df <- as.data.frame(sampleNumber)
currentWave_df$currentWave <- currentWave
# Plot wave to verify shape and parameters
plot <- ggplot(data=currentWave_df, aes(x=sampleNumber, y=currentWave)) +
geom_line(color="blue")
plot <- ggplotly(plot) # Turn to an interactive plot
plot # display the plot